import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import myindex from '@/components/myindex'
import myreg from '@/components/myreg'
import mylogin from '@/components/mylogin'
import myhome from '@/components/myhome'
import showcate from '@/components/showcate'
import addcourse from '@/components/addcourse'
import courselist from '@/components/courselist'
import coursedetail from '@/components/coursedetail'
import myback from '@/components/myback'
import ant_reg from '@/components/ant_reg'
import chat from '@/components/chatroom'


Vue.use(Router)

var routes = [
        {
          path:'/',
          name:'myindex',
          component:myindex
        },
        {
          path:'/myindex',
          name:'myindex',
          component:myindex
        },
        {
          path:'/chat',
          name:'chat',
          component:chat
        },
        {
          path:'/myback',
          name:'myback',
          component:myback
        },
        {
          path:'/myreg',
          name:'myreg',
          component:myreg
        },
        {
          path:'/ant_reg',
          name:'ant_reg',
          component:ant_reg
        },
        {
          path:'/courselist',
          name:'courselist',
          component:courselist
        },
        {
          path:'/coursedetail',
          name:'coursedetail',
          component:coursedetail
        },
         {
          path:'/addcourse',
          name:'addcourse',
          component:addcourse
        },
        {
          path:'/mylogin',
          name:'mylogin',
          component:mylogin
        },
        {
          path:'/showcate',
          name:'showcate',
          component:showcate
        },
        {
          path:'/myhome',
          name:'myhome',
          component:myhome,
          //拦截器使用
          beforeEnter:(to,from,next) => {

              if(localStorage.getItem("username")){
                  console.log('登录了');
                  next();
              }else{
                next('/mylogin');
              }

          }
        }
        
]

export default new Router({
  routes:routes,
  mode:'hash'   /*hash*/
})
